<?php
/**
 * check image exist, get size, display on the view
 */
class checkFileHelper extends AppHelper {

	/**
	 * convert file size to MB or KB
	 * @param $filesize
	 * @return string
	 */
	function set_fileSizeString($filesize) {
		$str = "";
		if ($filesize > 0) {
				
			$s = ceil($filesize/1024);
				
			if (($s/1024) >= 1) {

				$s = round($s/1024, 1);

				$str = $s."MB";
			} else {

				$str = $s."KB";
			}
				
		}else{
			$str = "0KB";
		}

		return $str;

	}

	/**
	 * Function get baseUrl
	 */
	public function baseUrl(){
		$pageURL = 'http';
		if ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTP_X_FORWARDED_PROTO"] == 'https') {
			$pageURL .= "s";
		}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$pageURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"];
		} else {
			$pageURL .= $_SERVER["HTTP_HOST"];
		}
		return $pageURL;
	}
}
?>